package com.fdd;

import com.fdd.dao.SakilaCountryMapper;
import com.fdd.pojo.SakilaCountry;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException {
        System.out.println( "Hello World!" );
        String resource = "MybatisConfig.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try(SqlSession sqlSession = sqlSessionFactory.openSession()) {
            SakilaCountryMapper sakilaCountryMapper = sqlSession.getMapper(SakilaCountryMapper.class);
            SakilaCountry sakilaCountry = sakilaCountryMapper.SelectOne(4);
            System.out.println(sakilaCountry);
        }

    }
}
